import { EntityManager } from "@mikro-orm/mariadb";
import { Application } from "express";

export default class BaseModel {
  get em() {
    // return this.app.em;
    return this.app.em.fork();
  }

  get gem() {
    return this.app.em;
  }

  app: Application;

  entityName: string;

  constructor(app: Application, entityName: string) {
    this.entityName = entityName;
    this.app = app;
  }

  async list() {
    // To fetch entities from database you can use find() and findOne() of EntityManager:
    return await this.em.findAll(this.entityName);
  }
}
